package com.linsir.lin.controller.meta;

import com.linsir.lin.dto.MetaObjectDTO;
import com.linsir.lin.service.MetaObjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.lang.reflect.InvocationTargetException;

/**
 * @author ：linsir
 * @date ：Created in 2021/7/1 10:39
 * @description：模型对象
 * @modified By：
 * @version: 1.0.0
 */

@Controller
@RequestMapping(value = "/admin")
public class OFController {

    @Autowired
    private MetaObjectService metaObjectService;
    /**
     *
     * 模型对象列表
     * */

    @RequestMapping(value = "/metaObject",method = {RequestMethod.GET,RequestMethod.POST})
    public String metaObject()
    {
        return "meta/metaObject";
    }

    @RequestMapping(value = "/metaObject/add")
    public String metaObjectAdd()
    {
        return "meta/metaObject_add";
    }


    /**
     *
     * 模型对象属性
     */

    @RequestMapping(value = "/metaField/addByObject/{code}",method = {RequestMethod.GET,RequestMethod.POST})
    public  String metaFieldaddByObject(@PathVariable("code") String code, ModelMap modelMap) throws InvocationTargetException, IllegalAccessException {
        if (code!=null)
        {

            MetaObjectDTO metaObjectDTO = metaObjectService.getMetaObjectDTOByCode(code);
            modelMap.addAttribute("metaObjectDTO",metaObjectDTO);
        }
        return "meta/metaField_addByObject";
    }


    @RequestMapping(value = "/metaField",method = {RequestMethod.GET,RequestMethod.POST})
    public  String metaField(){
        return "meta/metaField";
    }
}
